package com.automannn.springPractice.applicationContext.bean.init;

import com.automannn.springPractice.applicationContext.bean.factory.UserFactory;
import com.automannn.springPractice.applicationContext.bean.factory.impl.DefaultUserFactory;
import org.springframework.beans.factory.config.SingletonBeanRegistry;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class BeanRegisterDemo {
    // BeanDefinitionBuilder
    public static void main(String[] args) {
        // AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        // ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        // UserFactory factory = new DefaultUserFactory();
        // beanFactory.registerSingleton("userFactory", factory);
        // context.refresh();
        // UserFactory userFactory = context.getBean("userFactory", UserFactory.class);
        // System.out.println("userFactory==factory:" + (userFactory == factory));
        // context.close();

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        SingletonBeanRegistry beanFactory = context.getBeanFactory();
        UserFactory factory = new DefaultUserFactory();
        beanFactory.registerSingleton("userFactory", factory);
        context.refresh();
        UserFactory userFactory = context.getBean("userFactory", UserFactory.class);
        System.out.println("userFactory==factory:" + (userFactory == factory));
        context.close();

    }
}
